﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        public static Dictionary<int, Student> list = new Dictionary<int, Student>();
        static void Main(string[] args)
        {
          
            list.Add(1,new Student(1,"张三",20));
            list.Add(3,new Student(3,"李四",23));
            list.Add(2,new Student(2,"阿斯顿",19));
            
            
            while (true)
            {
                Console.WriteLine("请选择：1、添加学生信息。2、查询学生信息。3、删除学生信息。4、退出");
                string t = Console.ReadLine();
                //用户输入后 进行判断 要执行的操作
                switch (t)
                {
                    case "1":
                        Add();
                        break;
                    case "2":
                        Find();
                        break;
                    case "3":
                        Delete();
                        break;
                    case "4":
                        Console.WriteLine("再见！！！");
                       
                        return;
                    default:
                        
                        Console.WriteLine("输入错误，请重新输入");
                        break;
                }
            }

        }

        private static void Delete()
        {
            Console.WriteLine("请输入学生学号");
            int num = int.Parse(Console.ReadLine());
            if (!list.ContainsKey(num))
            {
                Console.WriteLine("学号不存在，请重新输入");
                return;
            }
            list.Remove(num);
            Console.WriteLine("删除成功！");
        }
    

        private static void Find()
        {
            Console.WriteLine("请选择：1、查询所有（按学号排序），2、查询所有（按姓名排序），3、查询所有（按年龄排序），4、按学号查询 ，5、退出");
            string t = Console.ReadLine();
            //用户输入后 进行判断 要执行的操作
            switch (t)
            {
                case "1":
                    List<Student> alist1 = new List<Student>();
                    foreach (var value in list.Values)
                    {
                        alist1.Add(value);
                    }
                    alist1.Sort(new IdSort());
                    foreach (var item in alist1)
                    {
                        Console.WriteLine(item);
                    }
                    break;
                case "2":
                    List<Student> alist2 = new List<Student>();
                    foreach (var value in list.Values)
                    {
                        alist2.Add(value);
                    }
                    alist2.Sort(new NameSort());
                    foreach (var item in alist2)
                    {
                        Console.WriteLine(item);
                    }
                    break;
                case "3":
                    List<Student> alist3 = new List<Student>();
                    foreach (var value in list.Values)
                    {
                        alist3.Add(value);
                    }
                    alist3.Sort(new AgeSort());
                    foreach (var item in alist3)
                    {
                        Console.WriteLine(item);
                    }
                    break;
                case "4":
                    Console.WriteLine("请输入学生学号");
                    int num = int.Parse(Console.ReadLine());
                    if (!list.ContainsKey(num))
                    {
                        Console.WriteLine("查无此学生");
                        return;
                    }
                    else
                    {
                        Console.WriteLine(list[num]);
                    }
                        break;
                case "5":
                    Console.WriteLine("感谢使用查询功能，再见!");
                 
                    return;
                default:

                    Console.WriteLine("输入错误，请重新输入");
                    break;
            }
        }

        private static void Add()
        {
            int a;

            while (true)
            {
                Console.WriteLine("请输入学生学号");
                a = int.Parse(Console.ReadLine());

                if (list.ContainsKey(a))
                {
                    Console.WriteLine("学号已存在，请重新输入");
                    continue;
                }
                break;
            }
            Console.WriteLine("请输入学生姓名");
            string name = Console.ReadLine();
            Console.WriteLine("请输入学生年龄");
            int age = int.Parse(Console.ReadLine());
            Student stu = new Student(a, name, age);
            list.Add(a, stu);
            Console.WriteLine("添加成功!");
        }
    }
   
}
    

